import 'dart:math';

import 'package:flutter/material.dart';
import 'package:vector_math/vector_math_64.dart';

class ShakeBuiltTransition extends StatelessWidget {
  const ShakeBuiltTransition({
    required this.controller,
    required this.child,
    this.cycleCount = 2,
    super.key,
  });

  final Widget child;
  final AnimationController controller;
  final int cycleCount;

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: controller,
      child: child,
      builder: (context, child) {
        final translation = Vector3(
          3 * sin(controller.value * 2 * pi * cycleCount),
          0.0,
          0.0,
        );

        return Transform(
          transform: Matrix4.translation(translation),
          child: child,
        );
      },
    );
  }
}
